#include "CResourceManager.h"

CResourceManager*	CResourceManager::m_pResourceManager = NULL;



CResourceManager::CResourceManager()
{
	m_pListImage = NULL;
	m_nListCount = 0;
}


CResourceManager::~CResourceManager()
{
	if( m_pListImage )
		delete [] m_pListImage;
	m_pListImage = NULL;
	m_nListCount = 0;
}




//-------------------------------------------//
// Name : CResourceManager					 //
// Desc : Retreat the instance of this class //
//-------------------------------------------//
CResourceManager* CResourceManager::GetInstance()
{
	if(m_pResourceManager == NULL)
	{
		m_pResourceManager = new CResourceManager();
	}

	return m_pResourceManager;
}



//----------------------------------//
// Name : Init						//
// Desc : Load image from .ini file	//
//----------------------------------//
void CResourceManager::Init(LPCTSTR DefineFile , CGraphic* pGraphic)
{
	char	Buffer[1025];
	char	Section[100];
	char	keyName[100];
	char	filePath[MAX_PATH];

	strcpy( Section , "Image" );

	m_nListCount = GetPrivateProfileInt( Section , "ImageCount" , 0 , DefineFile );
	m_pListImage = new CTexture[m_nListCount];

	for( ULONG i = 0 ; i < m_nListCount ; ++i )
	{
		_stprintf( keyName , _T("Image_%i") , i );
		GetPrivateProfileString( Section , keyName , "" , filePath , MAX_PATH - 1 , DefineFile );
		m_pListImage[i].LoadTextureFromFile( filePath , D3DCOLOR_XRGB(255,0,255) , pGraphic->GetDevice() , pGraphic->GetSpriteHandler() );
	}
}